package com.company.cloud.article.modules.mgr.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.company.cloud.article.modules.cache.models.ArticleModel;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ArticleMgrMapper {

	/**资讯（不含分类）*/
	@Select("select t1.article_no,t1.company_no as main_company_no,t1.title,t1.title_en as titleEn,t1.summary,t1.summary_en as summaryEn,t1.thumbnail," +
            "t1.style,t1.comment_status,t1.meta_keywords,t1.meta_description,t1.is_pub_platform,DATE_FORMAT(t1.edt,'%Y-%m-%d %H:%i:%s') as edt," +
            "t2.article_rel_no,t2.company_no,t2.orders,t2.tags,t2.remarks,t2.comment_count," +
            "t2.comment_time,t2.view_count,t2.is_rel,t2.state,t2.rel_id, t2.rel_id_type " +
            "from cms_article_info t1 inner join cms_article_company_rel_info t2 " +
            "on (t1.article_no = t2.article_no and t1.rows_state='1' and t2.rows_state='1') " +
	        " ${ew.customSqlSegment}")
    public IPage<ArticleModel> queryArticle(IPage<ArticleModel> page, @Param(Constants.WRAPPER) Wrapper<ArticleModel> wrapper);


	/**资讯详细（不含分类）*/
	@Select("select t1.article_no,t1.company_no as main_company_no,t1.title,t1.title_en as titleEn,t1.content,t1.content_en as contentEn,t1.summary,t1.summary_en as summaryEn,t1.thumbnail," +
			"t1.style,t1.comment_status,t1.meta_keywords,t1.meta_description,t1.is_pub_platform,DATE_FORMAT(t1.edt,'%Y-%m-%d %H:%i:%s') as edt," +
			"t2.article_rel_no,t2.company_no,t2.orders,t2.tags,t2.remarks,t2.comment_count," +
			"t2.comment_time,t2.view_count,t2.is_rel, t2.state,t2.rel_id, t2.rel_id_type " +
			"from cms_article_info t1 inner join cms_article_company_rel_info t2 " +
			"on (t1.article_no = t2.article_no and t1.rows_state='1' and t2.rows_state='1') " +
			"${ew.customSqlSegment}")
	public IPage<ArticleModel> queryArticleFull(IPage<ArticleModel> page, @Param(Constants.WRAPPER) Wrapper<ArticleModel> wrapper);



	/**资讯 （分类）*/
	@Select("select t1.article_no,t1.company_no as main_company_no,t1.title ,t1.title_en as titleEn,t1.summary,t1.summary_en as summaryEn ,t1.thumbnail," +
			"t1.style,t1.comment_status,t1.meta_keywords,t1.meta_description,t1.is_pub_platform,DATE_FORMAT(t1.edt,'%Y-%m-%d %H:%i:%s') as edt," +
			"t2.article_rel_no,t2.company_no,t2.orders,t2.tags,t2.remarks,t2.comment_count," +
			"t2.comment_time,t2.view_count,t2.is_rel, t2.state,t2.rel_id, t2.rel_id_type " +
			"from cms_article_info t1 inner join cms_article_company_rel_info t2 on (t1.article_no = t2.article_no and t1.rows_state='1' and t2.rows_state='1')" +
			"inner join cms_article_category_mapping_info t3 on (t1.article_no = t3.article_no and t2.article_rel_no = t3.article_rel_no) " +
			"inner join cms_article_category_info t4 on (t3.category_id = t4.id) " +
			"${ew.customSqlSegment}")
	public IPage<ArticleModel> queryArticleByCategory(IPage<ArticleModel> page, @Param(Constants.WRAPPER) Wrapper<ArticleModel> wrapper);

	/**资讯详情（分类）*/
	@Select("select t1.article_no,t1.company_no as main_company_no,t1.title,t1.title_en as titleEn,t1.content,t1.content_en as contentEn,t1.summary,t1.summary_en as summaryEn,t1.thumbnail," +
			"t1.style,t1.comment_status,t1.meta_keywords,t1.meta_description,t1.is_pub_platform,DATE_FORMAT(t1.edt,'%Y-%m-%d %H:%i:%s') as edt ," +
			"t2.article_rel_no,t2.company_no,t2.orders,t2.tags,t2.remarks,t2.comment_count," +
			"t2.comment_time,t2.view_count,t2.is_rel, t2.state,t2.rel_id, t2.rel_id_type " +
			"from cms_article_info t1 inner join cms_article_company_rel_info t2 on (t1.article_no = t2.article_no and t1.rows_state='1' and t2.rows_state='1')" +
			"inner join cms_article_category_mapping_info t3 on (t1.article_no = t3.article_no and t2.article_rel_no = t3.article_rel_no) " +
			"inner join cms_article_category_info t4 on (t3.category_id = t4.id)" +
			"${ew.customSqlSegment}")
	public IPage<ArticleModel> queryArticleFullByCategory(IPage<ArticleModel> page, @Param(Constants.WRAPPER) Wrapper<ArticleModel> wrapper);



	@Select("select t1.article_no,t1.company_no as main_company_no,t1.title,t1.title,t1.title_en as titleEn,t1.content,t1.content_en as contentEn,t1.summary,t1.summary_en as summaryEn,t1.thumbnail," +
			"t1.style,t1.comment_status,t1.meta_keywords,t1.meta_description,t1.is_pub_platform," +
			"t2.article_rel_no,t2.company_no,t2.orders,t2.tags,remarks,t2.comment_count," +
			"t2.comment_time,t2.view_count,t2.is_rel, t2.state,t2.rel_id, t2.rel_id_type " +
			"from cms_article_info t1 inner join cms_article_company_rel_info t2 " +
			"on (t1.article_no = t2.article_no and t1.rows_state='1' and t2.rows_state='1') " +
			"${ew.customSqlSegment}")
	public List<ArticleModel> getArticleList(@Param(Constants.WRAPPER) Wrapper<ArticleModel> wrapper);


	@Select("select t1.category_id from cms_article_category_mapping_info t1 " +
			"INNER JOIN cms_article_category_info t2 on t1.category_id = t2.id and t2.rows_state='1' " +
			"where t1.article_no = #{articleNo}")
	public List<Integer> getArticlesCategory(@Param("articleNo") String articleNo);

}
